<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <!--          <a-col :xl="6" :lg="7" :md="8" :sm="24">-->
          <!--            <a-form-item label="仓库编号">-->
          <!--              <a-input placeholder="请输入仓库编号" v-model="queryParam.warehouseCode"></a-input>-->
          <!--            </a-form-item>-->
          <!--          </a-col>-->
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="库位">
              <j-dict-select-tag
                placeholder="请选择库位"
                v-model="queryParam.warehouseLocationCode"
                dictCode="erp_location,name,code"
              />
              <!--              <a-input placeholder="请输入库位编号" v-model="queryParam.warehouseLocationCode"></a-input>-->
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="物料名称">
              <j-input
                placeholder="请输入名称"
                v-model="queryParam.materialName"
              />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="条形码">
              <j-input
                placeholder="请输入条形码"
                v-model="queryParam.barcode"
              />
            </a-form-item>
          </a-col>
          <!-- <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="操作类型">
              <j-dict-select-tag
                placeholder="请选择操作类型"
                v-model="queryParam.operationCategory"
                dictCode="kc_operation_category"
              />
            </a-form-item>
          </a-col> -->
          <!--          <a-col :xl="10" :lg="11" :md="12" :sm="24">-->
          <!--            <a-form-item label="开始日期">-->
          <!--              <j-date placeholder="请选择开始日期" class="query-group-cust" v-model="queryParam.preparedTime_begin"></j-date>-->
          <!--              <span class="query-group-split-cust"></span>-->
          <!--              <j-date placeholder="请选择结束日期" class="query-group-cust" v-model="queryParam.preparedTime_end"></j-date>-->
          <!--            </a-form-item>-->
          <!--          </a-col>-->
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <!--              <a @click="handleToggleSearch" style="margin-left: 8px">-->
              <!--                {{ toggleSearchStatus ? '收起' : '展开' }}-->
              <!--                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>-->
              <!--              </a>-->
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator"></div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
        <a style="font-weight: 600">{{ selectedRowKeys.length }}</a
        >项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        class="j-table-force-nowrap1"
        :scroll="{ x: true }"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
        :rowClassName="setRowClassName"
        @change="handleTableChange"
      >
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text, record">
          <span v-if="!text" style="font-size: 12px; font-style: italic">无图片</span>
          <img
            v-else
            :src="getImgView(text)"
            :preview="record.id"
            height="25px"
            alt=""
            style="max-width: 80px; font-size: 12px; font-style: italic"
          />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">无文件</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="historyRow(record)">历史查询</a>
        </span>
      </a-table>
    </div>

    <!--    <buss-inventory-details-modal ref="modalForm" @ok="modalFormOk"/>-->
    <buss-in-out-detail-list-modal
      ref="selectInOutDetailList"
      :modalWidth="modalWidth"
      :code="code"
      :quantity="quantity"
      :category="category"
    >
    </buss-in-out-detail-list-modal>
  </a-card>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
// import BussInventoryDetailsModal from './modules/BussInventoryDetailsModal'
import { filterMultiDictText } from '@/components/dict/JDictSelectUtil'
import '@/assets/less/TableExpand.less'
import BussInOutDetailListModal from '@comp/base/modal/BussInOutDetailListModal'

export default {
  name: 'BussInventoryDetailsList',
  mixins: [JeecgListMixin],
  components: {
    // BussInventoryDetailsModal,
    BussInOutDetailListModal,
  },
  data() {
    return {
      description: '库存明细管理页面',
      modalWidth: 1300,
      category: '',
      code: '',
      quantity: '',
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '单据编号',
          align: 'center',
          dataIndex: 'code',
        },
        {
          title: '物料编号',
          align: 'center',
          dataIndex: 'materialCode',
        },
        {
          title: '物料名称',
          align: 'center',
          dataIndex: 'materialName',
        },
        {
          title: '规格型号',
          align: 'center',
          dataIndex: 'noneSpec',
        },
        {
          title: '单位',
          align: 'center',
          dataIndex: 'meUnit_dictText',
        },
        {
          title: '库存数量',
          align: 'center',
          dataIndex: 'quantity',
        },
        // {
        //   title:'入库数量',
        //   align:"center",
        //   dataIndex: 'inventoryQuantity'
        // },
        // {
        //   title:'出库数量',
        //   align:"center",
        //   dataIndex: 'outboundQuantity'
        // },
        {
          title: '占用数量',
          align: 'center',
          dataIndex: 'occupationQuantity',
        },
        // {
        //   title:'仓库编号',
        //   align:"center",
        //   dataIndex: 'warehouseCode'
        // },
        // {
        //   title:'仓库名称',
        //   align:"center",
        //   dataIndex: 'warehouseName'
        // },
        {
          title: '库位编号',
          align: 'center',
          dataIndex: 'warehouseLocationCode',
        },
        {
          title: '库位',
          align: 'center',
          dataIndex: 'warehouseLocation',
        },
        {
          title: '条形码',
          align: 'center',
          dataIndex: 'barcode',
        },
        {
          title: '批次号',
          align: 'center',
          dataIndex: 'batch',
        },
        {
          title: '物料批号',
          align: 'center',
          dataIndex: 'materialBatchNumber',
        },
        {
          title: '入库日期',
          align: 'center',
          dataIndex: 'inOutDate',
          customRender: function (text) {
            return !text ? '' : text.length > 10 ? text.substr(0, 10) : text
          },
        },
        {
          title: '生产日期',
          align: 'center',
          dataIndex: 'productionDate',
          customRender: function (text) {
            return !text ? '' : text.length > 10 ? text.substr(0, 10) : text
          },
        },
                {
          title: '限用日期',
          align: 'center',
          dataIndex: 'restrictedDate',
          customRender: function (text) {
            return !text ? '' : text.length > 10 ? text.substr(0, 10) : text
          },
        },
        {
          title: '状态',
          align: 'center',
          dataIndex: 'status_dictText',
        },
        {
          title: '质检状态',
          align: 'center',
          dataIndex: 'qualityInspectionStatus_dictText',
        },
        {
          title: '供应商编号',
          align: 'center',
          dataIndex: 'supplierCode',
        },
        {
          title: '供应商名称',
          align: 'center',
          dataIndex: 'supplierName',
        },
        {
          title: '宝洁供应商编码',
          align: 'left',
          dataIndex: 'bjSupplierCode',
          width: 120,
        },
        {
          title: '宝洁供应商',
          align: 'left',
          dataIndex: 'bjSupplier',
          width: 120,
        },
        {
          title: '宝洁单号',
          align: 'left',
          dataIndex: 'bjOder',
          width: 120,
        },
        {
          title: '辅助单位',
          align: 'center',
          dataIndex: 'auUnit_dictText',
        },
        {
          title: '辅助数量',
          align: 'center',
          dataIndex: 'auxiliaryQuantity',
        },
        {
          title: '制单人',
          align: 'center',
          dataIndex: 'preparedBy',
        },
        {
          title: '制单日期',
          align: 'center',
          dataIndex: 'preparedTime',
          customRender: function (text) {
            return !text ? '' : text.length > 10 ? text.substr(0, 10) : text
          },
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' },
        },
      ],
      url: {
        list: '/detail/bussInventoryDetails/list',
        delete: '/detail/bussInventoryDetails/delete',
        deleteBatch: '/detail/bussInventoryDetails/deleteBatch',
        exportXlsUrl: '/detail/bussInventoryDetails/exportXls',
        importExcelUrl: 'detail/bussInventoryDetails/importExcel',
      },
      dictOptions: {},
      superFieldList: [],
    }
  },
  created() {
    this.getSuperFieldList()
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    historyRow(row) {
      this.category = row.id
      this.code = row.code
      console.log("改变category")
      this.quantity = String(row.quantity)
      this.$refs.selectInOutDetailList.add()
      this.$refs.selectInOutDetailList.title = '查看库存明细'
      this.$refs.selectInOutDetailList.disableSubmit = false
    },
    initDictConfig() {},
    setRowClassName(record) {
      console.log(record)
      return record.qualityInspectionStatus === '2' ? 'clickRowStyle' : ''
    },
    getSuperFieldList() {
      let fieldList = []
      fieldList.push({ type: 'string', value: 'inventoryId', text: '库存ID', dictCode: '' })
      fieldList.push({ type: 'date', value: 'inOutDate', text: '出入库日期' })
      fieldList.push({ type: 'date', value: 'enterDate', text: '进厂日期' })
      fieldList.push({ type: 'date', value: 'restrictedDate', text: '限用日期' })
      fieldList.push({ type: 'date', value: 'productionDate', text: '生产日期' })
      fieldList.push({ type: 'string', value: 'workshop', text: '车间', dictCode: '' })
      fieldList.push({ type: 'string', value: 'warehouseCode', text: '仓库编号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'warehouseName', text: '仓库名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'warehouseLocation', text: '库位', dictCode: '' })
      fieldList.push({ type: 'string', value: 'warehouseLocationCode', text: '库位编号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'batch', text: '批次号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'materialBatchNumber', text: '物料批号', dictCode: '' })
      fieldList.push({ type: 'BigDecimal', value: 'inventoryQuantity', text: '入库数量', dictCode: '' })
      fieldList.push({ type: 'BigDecimal', value: 'outboundQuantity', text: '出库数量', dictCode: '' })
      fieldList.push({ type: 'BigDecimal', value: 'occupationQuantity', text: '占用数量', dictCode: '' })
      fieldList.push({ type: 'string', value: 'operationCategory', text: '操作类别', dictCode: '' })
      fieldList.push({ type: 'string', value: 'code', text: '单据编号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'materialId', text: '物料ID', dictCode: '' })
      fieldList.push({ type: 'string', value: 'materialCode', text: '物料编号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'materialName', text: '物料名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'noneSpec', text: '规格型号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'meUnit', text: '单位', dictCode: 'ji_unit' })
      fieldList.push({ type: 'BigDecimal', value: 'quantity', text: '库存数量', dictCode: '' })
      fieldList.push({ type: 'string', value: 'auUnit', text: '辅助单位', dictCode: 'zl_unit' })
      fieldList.push({ type: 'BigDecimal', value: 'auxiliaryQuantity', text: '辅助数量', dictCode: '' })
      fieldList.push({ type: 'string', value: 'qualityInspectionStatus', text: '质检状态', dictCode: 'zj_status' })
      fieldList.push({ type: 'string', value: 'remarks', text: '主表备注', dictCode: '' })
      fieldList.push({ type: 'string', value: 'subtableRemarks', text: '子表备注', dictCode: '' })
      fieldList.push({ type: 'string', value: 'status', text: '状态', dictCode: 'kc_status' })
      fieldList.push({ type: 'string', value: 'preparedBy', text: '制单人', dictCode: '' })
      fieldList.push({ type: 'date', value: 'preparedTime', text: '制单日期' })
      fieldList.push({ type: 'string', value: 'supplierId', text: '供应商', dictCode: 'erp_supplier,name,id' })
      fieldList.push({ type: 'string', value: 'supplierCode', text: '供应商编号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'supplierName', text: '供应商名称', dictCode: '' })
      this.superFieldList = fieldList
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
/deep/.clickRowStyle {
  background-color: red;
}
</style>